



import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios'

import {Ajax} from  '@/utils/ajax'



class MyData extends Component {

    state = {
        banners:[]
    }

    getBannersData = async ()=>{
        // let res = await axios.get('http://81.69.235.62:3000/app/banners')
        // if(res.data.code==200){
        //     this.setState({
        //         banners:res.data.result 
        //     })
        // }

        let res = await Ajax.get('http://81.69.235.62:3000/app/banners',
        {
            params:{
                id:1,
                page:1,
                pageSize:10
            },
            headers:{
                token:"WH2217-YYDS",
                xHost:"Are you OK",
                password:"ABC123"
            }
        }
        )
        if(res.data.code==200){
            this.setState({
                banners:res.data.result 
            })
        }

        let res2 = await Ajax.post('http://81.69.235.62:3000/app/getalltravels',{
            id:2217,
            pageSize:20,
            page:3,
        },{
            params:{
                name:'zkl',
            }
        })
        console.log(res2)

        // 增删改查
        // // get 请求列表 
        // let res3 = await  axios.get("http://localhost:5300/course")
        // console.log(res3)

        // // post  提交数据  
        // let res4 = await  axios.post("http://localhost:5300/course",{
        //     "course_name": "舒玛丽",
        //     "autor": "鹏展",
        //     "college": "霸道总擦",
        //     "category_Id": 3
        // })
        // console.log(res3)

        // delete 删除 
        // let res5 = await  axios({
        //     url:'http://localhost:5300/course/'+1002,
        //     method:"delete",
        // })
        // console.log(res5)

        // patch 批量修改 
        // let res5 = await  axios({
        //     url:'http://localhost:5300/course/'+1003,
        //     method:"patch",
        //     data:{
        //         "college": "霸道总裁小哥哥 - 2217 ",
        //     }
        // })
    }


    // 请求数据 
    componentDidMount(){
        this.getBannersData()
    }

    render() {
        return (
            <div>
                <h2>React 请求ajax 的流程 </h2>
                <div>
                    {
                        this.state.banners.map((item,index)=>(
                            <img key={index} style={{width:200,height:200,borderRadius:15,margin:15}} src={item.imgurl.replace(/public/, 'http://81.69.235.62:3000'  )} alt="" />
                        ))
                    }
                </div>
            </div>
        );
    }
}


MyData.propTypes = {

};


export default MyData;
